package dialogos;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.swing.BorderFactory;

import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;

import org.hibernate.collection.PersistentSet;

import paneles.PanelProfesionales;
import peluqueria.Peluqueria;
import accesoADatos.AccesoADatos;
import datos.Profesional;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ActualizarProfJDialog extends JDialog {


	private static final long serialVersionUID = 1L;

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				JFrame frame= new JFrame();
				ActualizarProfJDialog ap=new ActualizarProfJDialog(frame);
				ap.setVisible(true);
			}
		});
	}
	
	private JComboBox jComboBox1;
	private JPanel jPanel1;
	private PanelProfesionales datosProfPane1;
	@SuppressWarnings("unchecked")
	private Hashtable hashProf;

	@SuppressWarnings("unchecked")
	public ActualizarProfJDialog(JFrame frame) {
		super(frame,"Modificar Profesional");
		this.hashProf = new Hashtable();
		initGUI();
		

	}
	
	@SuppressWarnings("unchecked")
	private void initGUI() {
		try {
			
				this.setPreferredSize(new java.awt.Dimension(744, 530));
				BorderLayout thisLayout = new BorderLayout();
				getContentPane().setLayout(thisLayout);
				{
					jPanel1 = new JPanel();
					FlowLayout jPanel1Layout = new FlowLayout();
					jPanel1Layout.setHgap(10);
					jPanel1Layout.setVgap(15);
					jPanel1.setLayout(jPanel1Layout);
					getContentPane().add(jPanel1, BorderLayout.NORTH);
					jPanel1.setPreferredSize(new java.awt.Dimension(271, 50));;
					{
						List prof = AccesoADatos.getInstance().getProfesionalesTodos();
						jComboBox1 = new JComboBox();
						jPanel1.add(jComboBox1);
						jComboBox1.setPreferredSize(new java.awt.Dimension(200, 21));
						jComboBox1.setBackground(new java.awt.Color(255,255,255));
						jComboBox1.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));

						jComboBox1.addPopupMenuListener(new PopupMenuListener() {
							public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
								jComboBox1PopupMenuCanceled(evt);
							}
							@Override
							public void popupMenuCanceled(PopupMenuEvent e) {
								// TODO Auto-generated method stub
								
							}
							@Override
							public void popupMenuWillBecomeVisible(
									PopupMenuEvent e) {
								// TODO Auto-generated method stub
								
							}
					
						});
						for(int i=0; i<prof.size();i++){
							this.hashProf.put(((Profesional)prof.get(i)).getApellido()+" "+((Profesional)prof.get(i)).getNombre(), prof.get(i));
							jComboBox1.addItem(((Profesional)prof.get(i)).getApellido()+" "+((Profesional)prof.get(i)).getNombre());
							jPanel1.add(jComboBox1);
							;
							
						}
					}

				{
					datosProfPane1 = new PanelProfesionales();
					getContentPane().add(datosProfPane1, BorderLayout.CENTER);
					datosProfPane1.setPreferredSize(new java.awt.Dimension(736, 451));
					datosProfPane1.getBCancelar().addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							bCancelarActionPerformed(evt);
						}
					});
					datosProfPane1.getBAceptar().addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							bAceptarMouseClicked(evt);
						}
					});
				}
			}
			this.datosProfPane1.cargarProfesional((Profesional) this.hashProf.get(this.jComboBox1.getSelectedItem().toString()));
			pack();
			this.setSize(740, 540);
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void bAceptarMouseClicked(MouseEvent evt) {
		Profesional p=this.datosProfPane1.getProfesional();
		Profesional prof=(Profesional) this.hashProf.get(this.jComboBox1.getSelectedItem());
		prof.setApellido(p.getApellido());
		prof.setCelular(p.getCelular());
		prof.setDireccion(p.getDireccion());
		prof.setEstado(p.getEstado());
		prof.setNombre(p.getNombre());
		prof.setEmail(p.getEmail());
		prof.setPorcentajeColor(p.getPorcentajeColor());
		prof.setPorcentajeCorte(p.getPorcentajeCorte());
		prof.setTipoHorarioSemana(p.getTipoHorarioSemana());
		prof.setEntrada1(p.getEntrada1());
		prof.setEntrada2(p.getEntrada2());
		prof.setSalida1(p.getSalida1());
		prof.setSalida2(p.getSalida2());
		prof.setTipoHorarioViernes(p.getTipoHorarioViernes());
		prof.setEntrada1Viernes(p.getEntrada1Viernes());
		prof.setEntrada2Viernes(p.getEntrada2Viernes());
		prof.setSalida1Viernes(p.getSalida1Viernes());
		prof.setSalida2Viernes(p.getSalida2Viernes());
		prof.setTipoHorarioSabado(p.getTipoHorarioSabado());
		prof.setEntrada1Sabado(p.getEntrada1Sabado());
		prof.setEntrada2Sabado(p.getEntrada2Sabado());
		prof.setSalida1Sabado(p.getSalida1Sabado());
		prof.setSalida2Sabado(p.getSalida2Sabado());
		AccesoADatos.getInstance().setProfesional(prof);
		JOptionPane.showMessageDialog(this, "Se han actualizado los datos del profesional " + p);
		Peluqueria.getInstance().getCalendario().resizeTable();
		Peluqueria.getInstance().getpanelServicios().ActualizarProfesionales();
		Peluqueria.getInstance().getCalendario().ActualizarTurnos(Peluqueria.getInstance().getCalendario().getDate());
		this.dispose();
	}
	
	private void jComboBox1PopupMenuCanceled(PopupMenuEvent evt) {
		Profesional p=(Profesional) this.hashProf.get(this.jComboBox1.getSelectedItem());
		this.datosProfPane1.cargarProfesional(p);
	}
	
	private void bCancelarActionPerformed(ActionEvent evt) {
		this.dispose();
	}

}
